package schoolmath.web.components.content;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import schoolmath.web.entities.Presentation;

import javax.inject.Inject;

@Import(library = "context:/scripts/playPresentation.js")
public class PlayPresentationContent {

	private static Logger logger = LoggerFactory.getLogger(PlayPresentationContent.class);
	@Inject
	private JavaScriptSupport javaScriptSupport;
	@Persist(PersistenceConstants.FLASH)
	private Presentation presentation;

	public void afterRender() {
		javaScriptSupport.addScript("presentationId = " + presentation.getId());
		javaScriptSupport.addScript("startPlay()");
	}

	public Presentation getPresentation() {
		return this.presentation;
	}

	public void setPresentation(Presentation presentation) {
		this.presentation = presentation;
	}

	public Object onRefreshPage() {
		this.setPresentation(presentation);
		return this;
	}

}
